//
//  ProjectWindowController.m
//  SEOBox
//
//  Created by Syd on 10-3-1.
//  Copyright 2010 MusicPeace.ORG. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "ProjectWindowController.h"
#import "ProfileViewController.h"
#import "Project.h"

@implementation ProjectWindowController
@synthesize managedObjectContext;
@synthesize project;
@synthesize profileView;
@synthesize profileViewController;

- (id)init {
    if (![super initWithWindowNibName:@"ProjectWindow"]) return nil;
    return self;
}

- (void)dealloc {
    [managedObjectContext release];
    [project release];
    [profileView release];
    [profileViewController release];
    [super dealloc];
}

/*
- (void)awakeFromNib 
{
    CAAnimation *anim = [CABasicAnimation animation];
    [anim setDelegate:self];
    [self.window setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"alphaValue"]];
}
*/
- (void)showWindow:(id)sender
{NSLog(@"show window");
    // If the window was hidden, animate its alpha value so it fades in.
    if (![self.window isVisible])
    {
        self.window.alphaValue = 0.0;
        [self.window.animator setAlphaValue:1.0];
        
    }
    [super showWindow:sender];
}

- (BOOL)windowShouldClose:(id)window
{
    // Animate the window's alpha value so it fades out.
    [self.window.animator setAlphaValue:0.0];
    // Don't close the window immediately so we can see the animation.
    return NO;
}

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag 
{
    if(self.window.alphaValue == 0.00) [self close]; //detect end of fade out and close the window
}

- (void)windowWillClose:(NSNotification *)notification {
    [self release];
}

- (void)windowDidLoad {
    profileViewController = [[ProfileViewController alloc] init];
    profileViewController.project = self.project;
    profileViewController.managedObjectContext = self.managedObjectContext;
    [profileViewController.view setFrame: [profileView bounds]];
    [profileView addSubview:profileViewController.view];
}

@end
